package com.glsc.ngateway.common.base.converter.platform;

import com.alibaba.excel.util.CollectionUtils;
import com.glsc.ngateway.common.api.platform.dto.system.SystemMainDto;
import com.glsc.ngateway.common.base.domain.mysql.gateway.system.SystemMain;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author xuchang
 */
public class SystemMainConverter {

    public static SystemMainDto do2Dto(SystemMain domain) {
        if (Objects.isNull(domain)) {
            return null;
        }
        SystemMainDto dto = SystemMainMapper.INSTANCE.do2Dto(domain);
        dto.setContactInfo(SystemMainContactConverter.do2Dto(domain.getContactInfo()));
        return dto;
    }

    public static List<SystemMainDto> do2Dto(List<SystemMain> domainList) {
        return CollectionUtils.isEmpty(domainList) ? java.util.Collections.emptyList() : domainList.stream().map(SystemMainConverter::do2Dto).collect(Collectors.toList());
    }

    public static SystemMain dto2Do(SystemMainDto dto) {
        if (Objects.isNull(dto)) {
            return null;
        }
        SystemMain domain = SystemMainMapper.INSTANCE.dto2Do(dto);
        domain.setContactInfo(SystemMainContactConverter.dto2Do(dto.getContactInfo()));
        return domain;
    }

    public static List<SystemMain> dto2Do(List<SystemMainDto> dtoList) {
        return CollectionUtils.isEmpty(dtoList) ? java.util.Collections.emptyList() : dtoList.stream().map(SystemMainConverter::dto2Do).collect(Collectors.toList());
    }

    @Mapper(componentModel = "spring")
    public interface SystemMainMapper {

        SystemMainMapper INSTANCE = Mappers.getMapper(SystemMainMapper.class);

        SystemMainDto do2Dto(SystemMain domain);

        List<SystemMainDto> do2Dto(List<SystemMain> domain);

        SystemMain dto2Do(SystemMainDto dto);

        List<SystemMain> dto2Do(List<SystemMainDto> dto);
    }
}
